﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;

public partial class Admin_CandidateMaster : System.Web.UI.Page
{
    #region events
    
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
            GetData();
            GetActivityName();
            emailtemplatedropdown.Items.Insert(0, "--Select--");
            emailtemplatedropdown.SelectedIndex = 0;
            //Session["UserID"] = Guid.NewGuid();
        }
    }

    private void GetData()
    {
        if (hdnInput.Value == "search")
        {
            DataSet objDs = new DataSet();
            objDs = GetDataSet();
            DataView objDv = new DataView();
            objDv = objDs.Tables[0].DefaultView;
            //objDv.RowFilter = "CountryName  LIKE '*" + txtActivityTypeName.Text.Trim() + "*'";
            gvLanguage.DataSource = objDv;
        }
        else
        {
            gvLanguage.DataSource = GetDataSet();
        }
        gvLanguage.DataBind();
    }
    
    protected void gvSearchResult_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //throw new NotImplementedException();
        gvLanguage.PageIndex = e.NewPageIndex;
        GetData();
    }
 
    #endregion


    #region Methods
    private DataSet GetDataSet()
    {

        DataSet objDs=null;
        try
        {
            objDs = new CandidateDataBAL().GetCandidateDataBAL();
        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;
       
    }
    private DataSet GetActivityEmailTemplate()
    {
        DataSet objDs=null;
        try
        {
            objDs = new CandidateDataBAL().GetActivityEmailTemplateBAL();
        }
        catch (Exception exception)
        {
            exception.AddErrorToLog();// throw new ApplicationException(exception.Message);
        }
        return objDs;
    }

    private void GetActivityName()
    {

        DataSet objDs = new DataSet();
        objDs = GetActivityEmailTemplate();
        //DataView objDv = new DataView();
        //objDv = objDs.Tables[0].DefaultView;
        //objDv.RowFilter = "CountryName  LIKE '*" + txtActivityTypeName.Text.Trim() + "*'";
        //gvLanguage.DataSource = objDv;
        activitydropdown.DataSource = objDs;
        activitydropdown.DataBind();
        activitydropdown.Items.Insert(0, "--Select--");
        activitydropdown.SelectedIndex = 0;
    }  
  
    private void GetEmailTemplateName(int x)
    {
        DataSet objDs = new DataSet();
       CandidateDataBO objBO=new CandidateDataBO();
       objBO.GetId = x;
       if (objBO.GetId != 0)
       {
           objDs = new CandidateDataBAL().GetActivityEmailTemplateBAL(objBO.GetId);
           if (objDs != null)
           {
               emailtemplatedropdown.DataSource = objDs;
               emailtemplatedropdown.DataBind();
           }
       }
       
            //DataSet objDv = new DataSet();
        //objDv = objDs.Tables[0].DefaultView;
        //objDv.RowFilter = "CountryName  LIKE '*" + txtActivityTypeName.Text.Trim() + "*'";
        
        //gvLanguage.DataSource = objDv;
       //emailtemplatedropdown.SelectedIndex = objBO.GetId;
        //emailtemplatedropdown.DataBind();
        
    }


    



    protected void BtnClear_OnClick(object sender, EventArgs e)
    {
        //throw new NotImplementedException();
        activitydropdown.SelectedIndex = 0;
        emailtemplatedropdown.SelectedIndex = 0;
        emailstatus.SelectedIndex = 0;
        //txtLanguageId.Text = "";
        //GetData();
    }



    protected void BtnSearch_OnClick(object sender, EventArgs e)
    {
        hdnInput.Value = "search";
        GetData();
    }

  
   
#endregion

    protected void gvLanguage_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvLanguage.PageIndex = e.NewPageIndex;
        GetData();
       
        
    }



    //protected void gvLanguage_RowEditing(object sender, GridViewEditEventArgs e)
    //{
    //    gvLanguage.PageIndex = e.NewEditIndex;
    //    GetData();
    //}

    protected void activitydropdown_SelectedIndexChanged(object sender, EventArgs e)
    {
        int activityid = Convert.ToInt32(activitydropdown.SelectedIndex);
        if(activityid!=0)
        GetEmailTemplateName(activityid);
        
        }
  
}